
   class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }

class Solution4 {
    public ListNode middleNode(ListNode head) {
        ListNode node = head;
        int size = 0;
        while(node != null) {
            size++;
            node = node.next;
        }

        if(size == 0 || size == 1) return head;

        size /= 2;
        while(size-- > 0) {
            head = head.next;
        }

        return head;
    }
}